<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Spring Cloud Gateway 内置的过滤器工厂 | 阿毛的博客</title><meta name="keywords" content="gateway"><meta name="author" content="myl"><meta name="copyright" content="myl"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Spring Cloud Gateway 内置的过滤器工厂内置的过滤器工厂这里简单将Spring Cloud Gateway内置的所有过滤器工厂整理成了一张表格。如下：    过滤器工厂 作用 参数    AddRequestHeader 为原始请求添加Header Header的名称及值   AddRequestParameter 为原始请求添加请求参数 参数名称及值   AddResponse">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring Cloud Gateway 内置的过滤器工厂">
<meta property="og:url" content="https://gitee.com/tgreen/myl-mm.git/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/index.html">
<meta property="og:site_name" content="阿毛的博客">
<meta property="og:description" content="Spring Cloud Gateway 内置的过滤器工厂内置的过滤器工厂这里简单将Spring Cloud Gateway内置的所有过滤器工厂整理成了一张表格。如下：    过滤器工厂 作用 参数    AddRequestHeader 为原始请求添加Header Header的名称及值   AddRequestParameter 为原始请求添加请求参数 参数名称及值   AddResponse">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg">
<meta property="article:published_time" content="2022-05-09T09:04:19.065Z">
<meta property="article:modified_time" content="2022-05-09T11:33:00.915Z">
<meta property="article:author" content="myl">
<meta property="article:tag" content="gateway">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg"><link rel="shortcut icon" href="/myl-mm/img/favicon.png"><link rel="canonical" href="https://gitee.com/tgreen/myl-mm.git/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myl-mm/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/myl-mm/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Spring Cloud Gateway 内置的过滤器工厂',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-09 19:33:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myl-mm/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/myl-mm/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/myl-mm/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myl-mm/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/long1.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/myl-mm/">阿毛的博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myl-mm/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Spring Cloud Gateway 内置的过滤器工厂</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-05-09T09:04:19.065Z" title="发表于 2022-05-09 17:04:19">2022-05-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-09T11:33:00.915Z" title="更新于 2022-05-09 19:33:00">2022-05-09</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myl-mm/categories/springcloud/">springcloud</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Spring Cloud Gateway 内置的过滤器工厂"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Spring-Cloud-Gateway-内置的过滤器工厂"><a href="#Spring-Cloud-Gateway-内置的过滤器工厂" class="headerlink" title="Spring Cloud Gateway 内置的过滤器工厂"></a>Spring Cloud Gateway 内置的过滤器工厂</h1><h3 id="内置的过滤器工厂"><a href="#内置的过滤器工厂" class="headerlink" title="内置的过滤器工厂"></a>内置的过滤器工厂</h3><p>这里简单将Spring Cloud Gateway内置的所有过滤器工厂整理成了一张表格。如下：</p>
<table>
<thead>
<tr>
<th align="left">过滤器工厂</th>
<th align="left">作用</th>
<th align="left">参数</th>
</tr>
</thead>
<tbody><tr>
<td align="left">AddRequestHeader</td>
<td align="left">为原始请求添加Header</td>
<td align="left">Header的名称及值</td>
</tr>
<tr>
<td align="left">AddRequestParameter</td>
<td align="left">为原始请求添加请求参数</td>
<td align="left">参数名称及值</td>
</tr>
<tr>
<td align="left">AddResponseHeader</td>
<td align="left">为原始响应添加Header</td>
<td align="left">Header的名称及值</td>
</tr>
<tr>
<td align="left">DedupeResponseHeader</td>
<td align="left">剔除响应头中重复的值</td>
<td align="left">需要去重的Header名称及去重策略</td>
</tr>
<tr>
<td align="left">Hystrix</td>
<td align="left">为路由引入Hystrix的断路器保护</td>
<td align="left"><code>HystrixCommand</code>的名称</td>
</tr>
<tr>
<td align="left">FallbackHeaders</td>
<td align="left">为fallbackUri的请求头中添加具体的异常信息</td>
<td align="left">Header的名称</td>
</tr>
<tr>
<td align="left">PrefixPath</td>
<td align="left">为原始请求路径添加前缀</td>
<td align="left">前缀路径</td>
</tr>
<tr>
<td align="left">PreserveHostHeader</td>
<td align="left">为请求添加一个preserveHostHeader&#x3D;true的属性，路由过滤器会检查该属性以决定是否要发送原始的Host</td>
<td align="left">无</td>
</tr>
<tr>
<td align="left">RequestRateLimiter</td>
<td align="left">用于对请求限流，限流算法为令牌桶</td>
<td align="left">keyResolver、rateLimiter、statusCode、denyEmptyKey、emptyKeyStatus</td>
</tr>
<tr>
<td align="left">RedirectTo</td>
<td align="left">将原始请求重定向到指定的URL</td>
<td align="left">http状态码及重定向的url</td>
</tr>
<tr>
<td align="left">RemoveHopByHopHeadersFilter</td>
<td align="left">为原始请求删除IETF组织规定的一系列Header</td>
<td align="left">默认就会启用，可以通过配置指定仅删除哪些Header</td>
</tr>
<tr>
<td align="left">RemoveRequestHeader</td>
<td align="left">为原始请求删除某个Header</td>
<td align="left">Header名称</td>
</tr>
<tr>
<td align="left">RemoveResponseHeader</td>
<td align="left">为原始响应删除某个Header</td>
<td align="left">Header名称</td>
</tr>
<tr>
<td align="left">RewritePath</td>
<td align="left">重写原始的请求路径</td>
<td align="left">原始路径正则表达式以及重写后路径的正则表达式</td>
</tr>
<tr>
<td align="left">RewriteResponseHeader</td>
<td align="left">重写原始响应中的某个Header</td>
<td align="left">Header名称，值的正则表达式，重写后的值</td>
</tr>
<tr>
<td align="left">SaveSession</td>
<td align="left">在转发请求之前，强制执行<code>WebSession::save</code>操作</td>
<td align="left">无</td>
</tr>
<tr>
<td align="left">secureHeaders</td>
<td align="left">为原始响应添加一系列起安全作用的响应头</td>
<td align="left">无，支持修改这些安全响应头的值</td>
</tr>
<tr>
<td align="left">SetPath</td>
<td align="left">修改原始的请求路径</td>
<td align="left">修改后的路径</td>
</tr>
<tr>
<td align="left">SetResponseHeader</td>
<td align="left">修改原始响应中某个Header的值</td>
<td align="left">Header名称，修改后的值</td>
</tr>
<tr>
<td align="left">SetStatus</td>
<td align="left">修改原始响应的状态码</td>
<td align="left">HTTP 状态码，可以是数字，也可以是字符串</td>
</tr>
<tr>
<td align="left">StripPrefix</td>
<td align="left">用于截断原始请求的路径</td>
<td align="left">使用数字表示要截断的路径的数量</td>
</tr>
<tr>
<td align="left">Retry</td>
<td align="left">针对不同的响应进行重试</td>
<td align="left">retries、statuses、methods、series</td>
</tr>
<tr>
<td align="left">RequestSize</td>
<td align="left">设置允许接收最大请求包的大小。如果请求包大小超过设置的值，则返回 <code>413 Payload Too Large</code></td>
<td align="left">请求包大小，单位为字节，默认值为5M</td>
</tr>
<tr>
<td align="left">ModifyRequestBody</td>
<td align="left">在转发请求之前修改原始请求体内容</td>
<td align="left">修改后的请求体内容</td>
</tr>
<tr>
<td align="left">ModifyResponseBody</td>
<td align="left">修改原始响应体的内容</td>
<td align="left">修改后的响应体内容</td>
</tr>
<tr>
<td align="left">Default</td>
<td align="left">为所有路由添加过滤器</td>
<td align="left">过滤器工厂名称及值</td>
</tr>
</tbody></table>
<p><strong>Tips：</strong>每个过滤器工厂都对应一个实现类，并且这些类的名称必须以<code>GatewayFilterFactory</code>结尾，这是Spring Cloud Gateway的一个约定，例如<code>AddRequestHeader</code>对应的实现类为<code>AddRequestHeaderGatewayFilterFactory</code>。</p>
<hr>
<h4 id="1、AddRequestHeader-GatewayFilter-Factory"><a href="#1、AddRequestHeader-GatewayFilter-Factory" class="headerlink" title="1、AddRequestHeader GatewayFilter Factory"></a>1、AddRequestHeader GatewayFilter Factory</h4><p>为原始请求添加Header，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">add_request_header_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">AddRequestHeader=X-Request-Foo,</span> <span class="string">Bar</span></span><br></pre></td></tr></table></figure>

<p>为原始请求添加名为 <code>X-Request-Foo</code> ，值为 <code>Bar</code> 的请求头</p>
<h4 id="2、AddRequestParameter-GatewayFilter-Factory"><a href="#2、AddRequestParameter-GatewayFilter-Factory" class="headerlink" title="2、AddRequestParameter GatewayFilter Factory"></a>2、AddRequestParameter GatewayFilter Factory</h4><p>为原始请求添加请求参数及值，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">add_request_parameter_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">AddRequestParameter=foo,</span> <span class="string">bar</span></span><br></pre></td></tr></table></figure>

<p>为原始请求添加名为foo，值为bar的参数，即：<code>foo=bar</code></p>
<h4 id="3、AddResponseHeader-GatewayFilter-Factory"><a href="#3、AddResponseHeader-GatewayFilter-Factory" class="headerlink" title="3、AddResponseHeader GatewayFilter Factory"></a>3、AddResponseHeader GatewayFilter Factory</h4><p>为原始响应添加Header，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">add_response_header_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">AddResponseHeader=X-Response-Foo,</span> <span class="string">Bar</span></span><br></pre></td></tr></table></figure>

<p>为原始响应添加名为 <code>X-Request-Foo</code> ，值为 <code>Bar</code> 的响应头</p>
<h4 id="4、DedupeResponseHeader-GatewayFilter-Factory"><a href="#4、DedupeResponseHeader-GatewayFilter-Factory" class="headerlink" title="4、DedupeResponseHeader GatewayFilter Factory"></a>4、DedupeResponseHeader GatewayFilter Factory</h4><p>DedupeResponseHeader可以根据配置的Header名称及去重策略剔除响应头中重复的值，这是Spring Cloud Greenwich SR2提供的新特性，低于这个版本无法使用。</p>
<p>我们在Gateway以及微服务上都设置了CORS（解决跨域）Header的话，如果不做任何配置，那么请求 -&gt; 网关 -&gt; 微服务，获得的CORS Header的值，就将会是这样的：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">Access-Control-Allow-Credentials: <span class="literal">true</span>, <span class="literal">true</span></span><br><span class="line">Access-Control-Allow-Origin: https://musk.mars, https://musk.mars</span><br></pre></td></tr></table></figure>

<p>可以看到这两个Header的值都重复了，若想把这两个Header的值去重的话，就需要使用到DedupeResponseHeader，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">dedupe_response_header_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="comment"># 若需要去重的Header有多个，使用空格分隔</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">DedupeResponseHeader=Access-Control-Allow-Credentials</span> <span class="string">Access-Control-Allow-Origin</span></span><br></pre></td></tr></table></figure>

<p>去重策略：</p>
<ul>
<li>RETAIN_FIRST：默认值，保留第一个值</li>
<li>RETAIN_LAST：保留最后一个值</li>
<li>RETAIN_UNIQUE：保留所有唯一值，以它们第一次出现的顺序保留</li>
</ul>
<p>若想对该过滤器工厂有个比较全面的了解的话，建议阅读该过滤器工厂的源码，因为源码里有详细的注释及示例，比官方文档写得还好：<code>org.springframework.cloud.gateway.filter.factory.DedupeResponseHeaderGatewayFilterFactory</code></p>
<h4 id="5、Hystrix-GatewayFilter-Factory"><a href="#5、Hystrix-GatewayFilter-Factory" class="headerlink" title="5、Hystrix GatewayFilter Factory"></a>5、Hystrix GatewayFilter Factory</h4><p>为路由引入Hystrix的断路器保护，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">hystrix_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Hystrix=myCommandName</span></span><br></pre></td></tr></table></figure>

<p>Hystrix是Spring Cloud第一代容错组件，不过已经进入维护模式，未来Hystrix会被Spring Cloud移除掉，取而代之的是Alibaba Sentinel&#x2F;Resilience4J。所以本文不做详细介绍了，感兴趣的话可以参考官方文档：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#hystrix">Hystrix GatewayFilter Factory</a></li>
</ul>
<h4 id="6、FallbackHeaders-GatewayFilter-Factory"><a href="#6、FallbackHeaders-GatewayFilter-Factory" class="headerlink" title="6、FallbackHeaders GatewayFilter Factory"></a>6、FallbackHeaders GatewayFilter Factory</h4><p>同样是对Hystrix的支持，上一小节所介绍的过滤器工厂支持一个配置参数：<code>fallbackUri</code>，该配置用于当发生异常时将请求转发到一个特定的uri上。而<code>FallbackHeaders</code>这个过滤工厂可以在转发请求到该uri时添加一个Header，这个Header的值为具体的异常信息。配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">ingredients</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">lb://ingredients</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Path=//ingredients/**</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Hystrix</span></span><br><span class="line">          <span class="attr">args:</span></span><br><span class="line">            <span class="attr">name:</span> <span class="string">fetchIngredients</span></span><br><span class="line">            <span class="attr">fallbackUri:</span> <span class="string">forward:/fallback</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">ingredients-fallback</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">http://localhost:9994</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Path=/fallback</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">FallbackHeaders</span></span><br><span class="line">          <span class="attr">args:</span></span><br><span class="line">            <span class="attr">executionExceptionTypeHeaderName:</span> <span class="string">Test-Header</span></span><br></pre></td></tr></table></figure>

<p>这里也不做详细介绍了，感兴趣可以参考官方文档：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#fallback-headers">FallbackHeaders GatewayFilter Factory</a></li>
</ul>
<h4 id="7、PrefixPath-GatewayFilter-Factory"><a href="#7、PrefixPath-GatewayFilter-Factory" class="headerlink" title="7、PrefixPath GatewayFilter Factory"></a>7、PrefixPath GatewayFilter Factory</h4><p>为原始的请求路径添加一个前缀路径，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">prefixpath_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">PrefixPath=/mypath</span></span><br></pre></td></tr></table></figure>

<p>该配置使访问<code>$&#123;GATEWAY_URL&#125;/hello</code> 会转发到<code>https://example.org/mypath/hello</code></p>
<h4 id="8、PreserveHostHeader-GatewayFilter-Factory"><a href="#8、PreserveHostHeader-GatewayFilter-Factory" class="headerlink" title="8、PreserveHostHeader GatewayFilter Factory"></a>8、PreserveHostHeader GatewayFilter Factory</h4><p>为请求添加一个preserveHostHeader&#x3D;true的属性，路由过滤器会检查该属性以决定是否要发送原始的Host Header。配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">preserve_host_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">PreserveHostHeader</span></span><br></pre></td></tr></table></figure>

<p>如果不设置，那么名为 <code>Host</code> 的Header将由Http Client控制</p>
<h4 id="9、RequestRateLimiter-GatewayFilter-Factory"><a href="#9、RequestRateLimiter-GatewayFilter-Factory" class="headerlink" title="9、RequestRateLimiter GatewayFilter Factory"></a>9、RequestRateLimiter GatewayFilter Factory</h4><p>用于对请求进行限流，限流算法为令牌桶。配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">requestratelimiter_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">RequestRateLimiter</span></span><br><span class="line">          <span class="attr">args:</span></span><br><span class="line">            <span class="attr">redis-rate-limiter.replenishRate:</span> <span class="number">10</span></span><br><span class="line">            <span class="attr">redis-rate-limiter.burstCapacity:</span> <span class="number">20</span></span><br></pre></td></tr></table></figure>

<p>由于另一篇文章中已经介绍过如何使用该过滤器工厂实现网关限流，所以这里就不再赘述了：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://blog.51cto.com/zero01/2430532">Spring Cloud Gateway - 扩展</a></li>
</ul>
<p>或者参考官方文档：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#_requestratelimiter_gatewayfilter_factory">RequestRateLimiter GatewayFilter Factory</a></li>
</ul>
<h4 id="10、RedirectTo-GatewayFilter-Factory"><a href="#10、RedirectTo-GatewayFilter-Factory" class="headerlink" title="10、RedirectTo GatewayFilter Factory"></a>10、RedirectTo GatewayFilter Factory</h4><p>将原始请求重定向到指定的Url，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">redirect_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">RedirectTo=302,</span> <span class="string">https://acme.org</span></span><br></pre></td></tr></table></figure>

<p>该配置使访问 <code>$&#123;GATEWAY_URL&#125;/hello</code> 会被重定向到 <code>https://acme.org/hello</code> ，并且携带一个 <code>Location:http://acme.org</code> 的Header，而返回客户端的HTTP状态码为302</p>
<p>注意事项：</p>
<ul>
<li>HTTP状态码应为3xx，例如301</li>
<li>URL必须是合法的URL，该URL会作为<code>Location</code> Header的值</li>
</ul>
<h4 id="11、RemoveHopByHopHeadersFilter-GatewayFilter-Factory"><a href="#11、RemoveHopByHopHeadersFilter-GatewayFilter-Factory" class="headerlink" title="11、RemoveHopByHopHeadersFilter GatewayFilter Factory"></a>11、RemoveHopByHopHeadersFilter GatewayFilter Factory</h4><p>为原始请求删除<a target="_blank" rel="noopener" href="https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-7.1.3">IETF</a>组织规定的一系列Header，默认删除的Header如下：</p>
<ul>
<li>Connection</li>
<li>Keep-Alive</li>
<li>Proxy-Authenticate</li>
<li>Proxy-Authorization</li>
<li>TE</li>
<li>Trailer</li>
<li>Transfer-Encoding</li>
<li>Upgrade</li>
</ul>
<p>可以通过配置去指定仅删除哪些Header，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">filter:</span></span><br><span class="line">        <span class="attr">remove-hop-by-hop:</span></span><br><span class="line">          <span class="comment"># 多个Header使用逗号（,）分隔</span></span><br><span class="line">          <span class="attr">headers:</span> <span class="string">Connection,Keep-Alive</span></span><br></pre></td></tr></table></figure>

<h4 id="12、RemoveRequestHeader-GatewayFilter-Factory"><a href="#12、RemoveRequestHeader-GatewayFilter-Factory" class="headerlink" title="12、RemoveRequestHeader GatewayFilter Factory"></a>12、RemoveRequestHeader GatewayFilter Factory</h4><p>为原始请求删除某个Header，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">removerequestheader_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">RemoveRequestHeader=X-Request-Foo</span></span><br></pre></td></tr></table></figure>

<p>删除原始请求中名为 <code>X-Request-Foo</code> 的请求头</p>
<h4 id="13、RemoveResponseHeader-GatewayFilter-Factory"><a href="#13、RemoveResponseHeader-GatewayFilter-Factory" class="headerlink" title="13、RemoveResponseHeader GatewayFilter Factory"></a>13、RemoveResponseHeader GatewayFilter Factory</h4><p>为原始响应删除某个Header，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">removeresponseheader_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">RemoveResponseHeader=X-Response-Foo</span></span><br></pre></td></tr></table></figure>

<p>删除原始响应中名为 <code>X-Request-Foo</code> 的响应头</p>
<h4 id="14、RewritePath-GatewayFilter-Factory"><a href="#14、RewritePath-GatewayFilter-Factory" class="headerlink" title="14、RewritePath GatewayFilter Factory"></a>14、RewritePath GatewayFilter Factory</h4><p>通过正则表达式重写原始的请求路径，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">rewritepath_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Path=/foo/**</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="comment"># 参数1为原始路径的正则表达式，参数2为重写后路径的正则表达式</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">RewritePath=/foo/(?&lt;segment&gt;.*),</span> <span class="string">/$\&#123;segment&#125;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>该配置使得访问 <code>/foo/bar</code> 时，会将路径重写为<code>/bar</code> 再进行转发，也就是会转发到 <code>https://example.org/bar</code>。需要注意的是：由于YAML语法，需用<code>$\</code> 替换 <code>$</code></p>
<h4 id="15、RewriteResponseHeader-GatewayFilter-Factory"><a href="#15、RewriteResponseHeader-GatewayFilter-Factory" class="headerlink" title="15、RewriteResponseHeader GatewayFilter Factory"></a>15、RewriteResponseHeader GatewayFilter Factory</h4><p>重写原始响应中的某个Header，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">rewriteresponseheader_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="comment"># 参数1为Header名称，参数2为值的正则表达式，参数3为重写后的值</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">RewriteResponseHeader=X-Response-Foo,</span> <span class="string">password=[^&amp;]+,</span> <span class="string">password=***</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>该配置的意义在于：如果响应头中 <code>X-Response-Foo</code> 的值为<code>/42?user=ford&amp;password=omg!what&amp;flag=true</code>，那么就会被按照配置的值重写成<code>/42?user=ford&amp;password=***&amp;flag=true</code>，也就是把其中的<code>password=omg!what</code>重写成了<code>password=***</code></p>
<h4 id="16、SaveSession-GatewayFilter-Factory"><a href="#16、SaveSession-GatewayFilter-Factory" class="headerlink" title="16、SaveSession GatewayFilter Factory"></a>16、SaveSession GatewayFilter Factory</h4><p>在转发请求之前，强制执行<code>WebSession::save</code>操作，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">save_session</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Path=/foo/**</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">SaveSession</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>主要用在那种像 Spring Session 延迟数据存储（数据不是立刻持久化）的，并希望在请求转发前确保session状态保存情况。如果你将Spring Secutiry于Spring Session集成使用，并想确保安全信息都传到下游机器，你就需要配置这个filter。</p>
<h4 id="17、secureHeaders-GatewayFilter-Factory"><a href="#17、secureHeaders-GatewayFilter-Factory" class="headerlink" title="17、secureHeaders GatewayFilter Factory"></a>17、secureHeaders GatewayFilter Factory</h4><p>secureHeaders过滤器工厂主要是参考了<a target="_blank" rel="noopener" href="https://blog.appcanary.com/2017/http-security-headers.html">这篇博客</a>中的建议，为原始响应添加了一系列起安全作用的响应头。默认会添加如下Headers（包括值）：</p>
<ul>
<li><code>X-Xss-Protection:1; mode=block</code></li>
<li><code>Strict-Transport-Security:max-age=631138519</code></li>
<li><code>X-Frame-Options:DENY</code></li>
<li><code>X-Content-Type-Options:nosniff</code></li>
<li><code>Referrer-Policy:no-referrer</code></li>
<li><code>Content-Security-Policy:default-src &#39;self&#39; https:; font-src &#39;self&#39; https: data:; img-src &#39;self&#39; https: data:; object-src &#39;none&#39;; script-src https:; style-src &#39;self&#39; https: &#39;unsafe-inline&#39;</code></li>
<li><code>X-Download-Options:noopen</code></li>
<li><code>X-Permitted-Cross-Domain-Policies:none</code></li>
</ul>
<p>如果你想修改这些Header的值，那么就需要使用这些Headers对应的后缀，如下：</p>
<ul>
<li><code>xss-protection-header</code></li>
<li><code>strict-transport-security</code></li>
<li><code>frame-options</code></li>
<li><code>content-type-options</code></li>
<li><code>referrer-policy</code></li>
<li><code>content-security-policy</code></li>
<li><code>download-options</code></li>
<li><code>permitted-cross-domain-policies</code></li>
</ul>
<p>配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">filter:</span></span><br><span class="line">        <span class="attr">secure-headers:</span></span><br><span class="line">          <span class="comment"># 修改 X-Xss-Protection 的值为 2; mode=unblock</span></span><br><span class="line">          <span class="attr">xss-protection-header:</span> <span class="number">2</span><span class="string">;</span> <span class="string">mode=unblock</span></span><br></pre></td></tr></table></figure>

<p>如果想禁用某些Header，可使用如下配置：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">filter:</span></span><br><span class="line">        <span class="attr">secure-headers:</span></span><br><span class="line">          <span class="comment"># 多个使用逗号（,）分隔</span></span><br><span class="line">          <span class="attr">disable:</span> <span class="string">frame-options,download-options</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="18、SetPath-GatewayFilter-Factory"><a href="#18、SetPath-GatewayFilter-Factory" class="headerlink" title="18、SetPath GatewayFilter Factory"></a>18、SetPath GatewayFilter Factory</h4><p>修改原始的请求路径，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">setpath_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Path=/foo/&#123;segment&#125;</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">SetPath=/&#123;segment&#125;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>该配置使访问 <code>$&#123;GATEWAY_URL&#125;/foo/bar</code> 时会转发到 <code>https://example.org/bar</code> ，也就是原本的<code>/foo/bar</code>被修改为了<code>/bar</code></p>
<h4 id="19、SetResponseHeader-GatewayFilter-Factory"><a href="#19、SetResponseHeader-GatewayFilter-Factory" class="headerlink" title="19、SetResponseHeader GatewayFilter Factory"></a>19、SetResponseHeader GatewayFilter Factory</h4><p>修改原始响应中某个Header的值，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">setresponseheader_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">SetResponseHeader=X-Response-Foo,</span> <span class="string">Bar</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>将原始响应中 <code>X-Response-Foo</code> 的值修改为 <code>Bar</code></p>
<h4 id="20、SetStatus-GatewayFilter-Factory"><a href="#20、SetStatus-GatewayFilter-Factory" class="headerlink" title="20、SetStatus GatewayFilter Factory"></a>20、SetStatus GatewayFilter Factory</h4><p>修改原始响应的状态码，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">setstatusstring_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="comment"># 字符串形式</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">SetStatus=BAD_REQUEST</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">setstatusint_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="comment"># 数字形式</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">SetStatus=401</span></span><br></pre></td></tr></table></figure>

<p>SetStatusd的值可以是数字，也可以是字符串。但一定要是Spring <code>HttpStatus</code> 枚举类中的值。上面这两种配置都可以返回401这个HTTP状态码。</p>
<h4 id="21、StripPrefix-GatewayFilter-Factory"><a href="#21、StripPrefix-GatewayFilter-Factory" class="headerlink" title="21、StripPrefix GatewayFilter Factory"></a>21、StripPrefix GatewayFilter Factory</h4><p>用于截断原始请求的路径，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">nameRoot</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">http://nameservice</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Path=/name/**</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="comment"># 数字表示要截断的路径的数量</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">StripPrefix=2</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>如上配置，如果请求的路径为 <code>/name/bar/foo</code> ，那么则会截断成<code>/foo</code>后进行转发 ，也就是会截断2个路径。</p>
<h4 id="22、Retry-GatewayFilter-Factory"><a href="#22、Retry-GatewayFilter-Factory" class="headerlink" title="22、Retry GatewayFilter Factory"></a>22、Retry GatewayFilter Factory</h4><p>针对不同的响应进行重试，例如可以针对HTTP状态码进行重试，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">retry_test</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">http://localhost:8080/flakey</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Host=*.retry.com</span></span><br><span class="line">        <span class="attr">filters:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Retry</span></span><br><span class="line">          <span class="attr">args:</span></span><br><span class="line">            <span class="attr">retries:</span> <span class="number">3</span></span><br><span class="line">            <span class="attr">statuses:</span> <span class="string">BAD_GATEWAY</span></span><br></pre></td></tr></table></figure>

<p>可配置如下参数：</p>
<ul>
<li><code>retries</code>：重试次数</li>
<li><code>statuses</code>：需要重试的状态码，取值在 <code>org.springframework.http.HttpStatus</code> 中</li>
<li><code>methods</code>：需要重试的请求方法，取值在 <code>org.springframework.http.HttpMethod</code> 中</li>
<li><code>series</code>：HTTP状态码序列，取值在 <code>org.springframework.http.HttpStatus.Series</code> 中</li>
</ul>
<h4 id="23、RequestSize-GatewayFilter-Factory"><a href="#23、RequestSize-GatewayFilter-Factory" class="headerlink" title="23、RequestSize GatewayFilter Factory"></a>23、RequestSize GatewayFilter Factory</h4><p>设置允许接收最大请求包的大小，配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">request_size_route</span></span><br><span class="line">      <span class="attr">uri:</span> <span class="string">http://localhost:8080/upload</span></span><br><span class="line">      <span class="attr">predicates:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">Path=/upload</span></span><br><span class="line">      <span class="attr">filters:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">RequestSize</span></span><br><span class="line">        <span class="attr">args:</span></span><br><span class="line">          <span class="comment"># 单位为字节</span></span><br><span class="line">          <span class="attr">maxSize:</span> <span class="number">5000000</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>如果请求包大小超过设置的值，则会返回 <code>413 Payload Too Large</code>以及一个<code>errorMessage</code></p>
<h4 id="24、Modify-Request-Body-GatewayFilter-Factory"><a href="#24、Modify-Request-Body-GatewayFilter-Factory" class="headerlink" title="24、Modify Request Body GatewayFilter Factory"></a>24、Modify Request Body GatewayFilter Factory</h4><p>在转发请求之前修改原始请求体内容，该过滤器工厂只能通过代码配置，不支持在配置文件中配置。代码示例：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="keyword">public</span> RouteLocator <span class="title function_">routes</span><span class="params">(RouteLocatorBuilder builder)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> builder.routes()</span><br><span class="line">        .route(<span class="string">&quot;rewrite_request_obj&quot;</span>, r -&gt; r.host(<span class="string">&quot;*.rewriterequestobj.org&quot;</span>)</span><br><span class="line">            .filters(f -&gt; f.prefixPath(<span class="string">&quot;/httpbin&quot;</span>)</span><br><span class="line">                .modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE,</span><br><span class="line">                    (exchange, s) -&gt; <span class="keyword">return</span> Mono.just(<span class="keyword">new</span> <span class="title class_">Hello</span>(s.toUpperCase())))).uri(uri))</span><br><span class="line">        .build();</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Hello</span> &#123;</span><br><span class="line">    String message;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">Hello</span><span class="params">()</span> &#123; &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">Hello</span><span class="params">(String message)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.message = message;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getMessage</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> message;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setMessage</span><span class="params">(String message)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.message = message;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Tips：该过滤器工厂处于 <strong>BETA</strong> 状态，未来API可能会变化，生产环境请慎用</p>
</blockquote>
<h4 id="25、Modify-Response-Body-GatewayFilter-Factory"><a href="#25、Modify-Response-Body-GatewayFilter-Factory" class="headerlink" title="25、Modify Response Body GatewayFilter Factory"></a>25、Modify Response Body GatewayFilter Factory</h4><p>可用于修改原始响应体的内容，该过滤器工厂同样只能通过代码配置，不支持在配置文件中配置。代码示例：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="keyword">public</span> RouteLocator <span class="title function_">routes</span><span class="params">(RouteLocatorBuilder builder)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> builder.routes()</span><br><span class="line">        .route(<span class="string">&quot;rewrite_response_upper&quot;</span>, r -&gt; r.host(<span class="string">&quot;*.rewriteresponseupper.org&quot;</span>)</span><br><span class="line">            .filters(f -&gt; f.prefixPath(<span class="string">&quot;/httpbin&quot;</span>)</span><br><span class="line">                .modifyResponseBody(String.class, String.class,</span><br><span class="line">                    (exchange, s) -&gt; Mono.just(s.toUpperCase()))).uri(uri)</span><br><span class="line">        .build();</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>Tips：该过滤器工厂处于 <strong>BETA</strong> 状态，未来API可能会变化，生产环境请慎用</p>
</blockquote>
<h4 id="26、Default-Filters"><a href="#26、Default-Filters" class="headerlink" title="26、Default Filters"></a>26、Default Filters</h4><p>Default Filters用于为所有路由添加过滤器工厂，也就是说通过Default Filter所配置的过滤器工厂会作用到所有的路由上。配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">default-filters:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">AddResponseHeader=X-Response-Default-Foo,</span> <span class="string">Default-Bar</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">PrefixPath=/httpbin</span></span><br></pre></td></tr></table></figure>

<hr>
<p>官方文档：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.1.0.RELEASE/single/spring-cloud-gateway.html#_gatewayfilter_factories">GatewayFilter Factories</a></li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://gitee.com/tgreen/myl-mm.git">myl</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://gitee.com/tgreen/myl-mm.git/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/">https://gitee.com/tgreen/myl-mm.git/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://gitee.com/tgreen/myl-mm.git" target="_blank">阿毛的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myl-mm/tags/gateway/">gateway</a></div><div class="post_share"><div class="social-share" data-image="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/"><img class="prev-cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="onerror=null;src='/myl-mm/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">RabbitMQ Windows 安装</div></div></a></div><div class="next-post pull-right"><a href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/"><img class="next-cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="onerror=null;src='/myl-mm/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Turbine</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myl-mm/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">myl</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/myl-mm/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/myl-mm/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/myl-mm/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><a id="card-info-btn" href="https://gitee.com/tgreen/"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎观看，又来一个！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Spring-Cloud-Gateway-%E5%86%85%E7%BD%AE%E7%9A%84%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82"><span class="toc-number">1.</span> <span class="toc-text">Spring Cloud Gateway 内置的过滤器工厂</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E7%9A%84%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82"><span class="toc-number">1.0.1.</span> <span class="toc-text">内置的过滤器工厂</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81AddRequestHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.1.</span> <span class="toc-text">1、AddRequestHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81AddRequestParameter-GatewayFilter-Factory"><span class="toc-number">1.0.1.2.</span> <span class="toc-text">2、AddRequestParameter GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3%E3%80%81AddResponseHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.3.</span> <span class="toc-text">3、AddResponseHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4%E3%80%81DedupeResponseHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.4.</span> <span class="toc-text">4、DedupeResponseHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5%E3%80%81Hystrix-GatewayFilter-Factory"><span class="toc-number">1.0.1.5.</span> <span class="toc-text">5、Hystrix GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6%E3%80%81FallbackHeaders-GatewayFilter-Factory"><span class="toc-number">1.0.1.6.</span> <span class="toc-text">6、FallbackHeaders GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7%E3%80%81PrefixPath-GatewayFilter-Factory"><span class="toc-number">1.0.1.7.</span> <span class="toc-text">7、PrefixPath GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8%E3%80%81PreserveHostHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.8.</span> <span class="toc-text">8、PreserveHostHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9%E3%80%81RequestRateLimiter-GatewayFilter-Factory"><span class="toc-number">1.0.1.9.</span> <span class="toc-text">9、RequestRateLimiter GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10%E3%80%81RedirectTo-GatewayFilter-Factory"><span class="toc-number">1.0.1.10.</span> <span class="toc-text">10、RedirectTo GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#11%E3%80%81RemoveHopByHopHeadersFilter-GatewayFilter-Factory"><span class="toc-number">1.0.1.11.</span> <span class="toc-text">11、RemoveHopByHopHeadersFilter GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#12%E3%80%81RemoveRequestHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.12.</span> <span class="toc-text">12、RemoveRequestHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#13%E3%80%81RemoveResponseHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.13.</span> <span class="toc-text">13、RemoveResponseHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#14%E3%80%81RewritePath-GatewayFilter-Factory"><span class="toc-number">1.0.1.14.</span> <span class="toc-text">14、RewritePath GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#15%E3%80%81RewriteResponseHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.15.</span> <span class="toc-text">15、RewriteResponseHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#16%E3%80%81SaveSession-GatewayFilter-Factory"><span class="toc-number">1.0.1.16.</span> <span class="toc-text">16、SaveSession GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#17%E3%80%81secureHeaders-GatewayFilter-Factory"><span class="toc-number">1.0.1.17.</span> <span class="toc-text">17、secureHeaders GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#18%E3%80%81SetPath-GatewayFilter-Factory"><span class="toc-number">1.0.1.18.</span> <span class="toc-text">18、SetPath GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#19%E3%80%81SetResponseHeader-GatewayFilter-Factory"><span class="toc-number">1.0.1.19.</span> <span class="toc-text">19、SetResponseHeader GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#20%E3%80%81SetStatus-GatewayFilter-Factory"><span class="toc-number">1.0.1.20.</span> <span class="toc-text">20、SetStatus GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#21%E3%80%81StripPrefix-GatewayFilter-Factory"><span class="toc-number">1.0.1.21.</span> <span class="toc-text">21、StripPrefix GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#22%E3%80%81Retry-GatewayFilter-Factory"><span class="toc-number">1.0.1.22.</span> <span class="toc-text">22、Retry GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#23%E3%80%81RequestSize-GatewayFilter-Factory"><span class="toc-number">1.0.1.23.</span> <span class="toc-text">23、RequestSize GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#24%E3%80%81Modify-Request-Body-GatewayFilter-Factory"><span class="toc-number">1.0.1.24.</span> <span class="toc-text">24、Modify Request Body GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#25%E3%80%81Modify-Response-Body-GatewayFilter-Factory"><span class="toc-number">1.0.1.25.</span> <span class="toc-text">25、Modify Response Body GatewayFilter Factory</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#26%E3%80%81Default-Filters"><span class="toc-number">1.0.1.26.</span> <span class="toc-text">26、Default Filters</span></a></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/" title="RabbitMQ Windows 安装"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="RabbitMQ Windows 安装"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/" title="RabbitMQ Windows 安装">RabbitMQ Windows 安装</a><time datetime="2022-05-09T09:04:30.600Z" title="发表于 2022-05-09 17:04:30">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/" title="Spring Cloud Gateway 内置的过滤器工厂"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Spring Cloud Gateway 内置的过滤器工厂"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/" title="Spring Cloud Gateway 内置的过滤器工厂">Spring Cloud Gateway 内置的过滤器工厂</a><time datetime="2022-05-09T09:04:19.065Z" title="发表于 2022-05-09 17:04:19">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/" title="Turbine"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Turbine"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/" title="Turbine">Turbine</a><time datetime="2022-05-09T09:04:13.000Z" title="发表于 2022-05-09 17:04:13">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/Eureka%20%E5%85%A8%E9%83%A8%E9%85%8D%E7%BD%AE%20/" title="Euraka配置详解"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Euraka配置详解"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/Eureka%20%E5%85%A8%E9%83%A8%E9%85%8D%E7%BD%AE%20/" title="Euraka配置详解">Euraka配置详解</a><time datetime="2022-05-09T09:03:49.699Z" title="发表于 2022-05-09 17:03:49">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="springBootday01"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01">springBootday01</a><time datetime="2022-05-09T09:03:15.476Z" title="发表于 2022-05-09 17:03:15">2022-05-09</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By myl</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myl-mm/js/utils.js"></script><script src="/myl-mm/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>